export interface ITreeNodeDto {
  key: string;
  title: string;
  children: ITreeNodeDto[];
  isLeaf: boolean;
}

export class TreeNodeDto implements ITreeNodeDto {
  key: string;
  title: string;
  children: ITreeNodeDto[];
  isLeaf: boolean;

  constructor(data?: ITreeNodeDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.key = data["key"];
      this.title = data["title"];
      this.children = data["children"];
      this.isLeaf = data["isLeaf"];

    }
  }

  static fromJS(data: any): TreeNodeDto {
    data = typeof data === 'object' ? data : {};
    let result = new TreeNodeDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["key"] = this.key;
    data["title"] = this.title;
    data["children"] = this.children;
    data["isLeaf"] = this.isLeaf;
    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new TreeNodeDto();
    result.init(json);
    return result;
  }
}




